package com.gliese.bambook.util;

import java.util.Vector;

import org.htmlparser.Attribute;
import org.htmlparser.tags.LinkTag;

public class LinkTagForBam extends LinkTag {
	@Override
	public String toTagHtml() {
		int length;
		int size;
		Vector attributes;
		Attribute attribute;
		StringBuffer ret;

		length = 2;
		attributes = getAttributesEx();
		size = attributes.size();
		for (int i = 0; i < size; i++) {
			attribute = (Attribute) attributes.elementAt(i);
			length += attribute.getLength();
		}
		ret = new StringBuffer(length);
		ret.append("<");
		for (int i = 0; i < size; i++) {
			attribute = (Attribute) attributes.elementAt(i);
			if ("=".equals(attribute.getAssignment()))
				attribute.setQuote('\"');
			if (attribute.getName()!=null&&(attribute.getName().toUpperCase()).equals("HREF")) {
				String mvalue = attribute.getValue().replace("&", "&amp;");
				attribute.setValue(mvalue);
			}
			attribute.toString(ret);
		}
		ret.append(">");

		return (ret.toString());
	}

}
